package com.atguigu.cloud.order.service.impl;

import com.atguigu.cloud.order.feign.UserOpenFeign;
import com.atguigu.cloud.order.mapper.OrderMapper;
import com.atguigu.cloud.order.pojo.Order;
import com.atguigu.cloud.order.pojo.User;
import com.atguigu.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper ;

    /*@Autowired
    private RestTemplate restTemplate;*/
    @Autowired
    private UserOpenFeign userOpenFeign;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        // 根据id查询订单数据
        Order order = orderMapper.findOrderByOrderId(orderId);
        // 发起远程调用
        // 服务提供方的服务ip地址和端口号可以使用服务提供方的服务名称进行替换
        /*User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + order.getUserId(), User.class);*/
        User user2 = userOpenFeign.findOrderByOrderId(order.getUserId());
        order.setUser(user2);
        // 返回订单数据
        return order;
    }
}